<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <h1>axios请求方法别名</h1>
    <button id="btnGet">发送查询get请求</button>
    <button id="btnPost">发送新增post请求</button>
    <button id="btnUpdate">发送更新update请求</button>
    <button id="btnDelete">发送删除delete请求</button>
    <script>
        let btnGet = document.querySelector('#btnGet')
        let btnPost = document.querySelector('#btnPost')
        let btnUpdate = document.querySelector('#btnUpdate')
        let btnDelete = document.querySelector('#btnDelete')
        /*axios.request(config)
        axios.get(url[, config])
        axios.delete(url[, config])
        axios.head(url[, config])
        axios.options(url[, config])
        axios.post(url[, data[, config]])
        axios.put(url[, data[, config]])
        axios.patch(url[, data[, config]]) */
        btnGet.onclick = async function () {
            let re = await axios.get('/user', {
                params: {
                    userid: '1'
                }
            })
            console.log(re.data);
        }

        btnPost.onclick = async function () {
            let re = await axios.post('/post', {
                name: 'peihua',
                age: '22',
                sex: '男'
            })
            console.log(re.data);
        }

        btnUpdate.onclick = async function(){
            let re = await axios.put('/put',{
                name: 'peihua',
                age: '22',
                sex: '男'
            })
            console.log(re.data);
        }

        btnDelete.onclick = async function(){
            let re = await axios.delete('/delete',{
                params:{
                    userid :'1'
                }
            })
            console.log(re.data);
        }
    </script>
</body>

</html>